<template>
  <div class="hFull flex column overflow-y multiple-select-text-questions-body pra">
    <div class="equal">
      <div class="radioBg pra">
        <!-- 题目 -->
        <div class="head">
          <div class="flex headBox aicenter jccenter">
            <div class="tips mr10"></div>
            <div class="equal fz16 overflow-y qtText">
              <span>{{question.guide}}</span>
            </div>
          </div>
        </div>
        <!-- 问题 -->
        <div class="selcect">
          <div class="equal overflow-y">
            <div class="warp">
              <div class="fz16 mb10" v-for="stem in question.stem" :key="stem">{{stem}}</div>
              <div class="warpTab mb10" v-for="(ms,msIndex) in question.multi_stem" :key="msIndex">
                <div class="fz16 mb10">{{ms.stem}}</div>
                <div class="tree pra">
                  <div class="treeDiv flex fz16 pra" @click="selectMenu(msIndex)">
                    <div class="equal">{{answer[msIndex]&&answer[msIndex]!==''?answer[msIndex]:'请选择'}}</div>
                    <div class="arrowDown">
                      <span></span>
                    </div>
                  </div>

                  <div class="treeBox" v-if="selectMenuIndex==msIndex">
                    <ul>
                      <li v-for="(opt,optIndex) in ms.option" :key="optIndex" @click="selectMenuItem(msIndex,optIndex)">{{opt}}</li>
                    </ul>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 提交按钮 -->
    <div class="submit pob" @click="submit(answer)"></div>
    <!-- 弹出 -->
    <div class="black none"></div>
    <div class="error none">
      <div class="flex aicenter jccenter errorImg">
        <img src="../assets/images/errorImg.png" alt />
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: ["submitAnswer", "question"],
  data() {
    return {
      answer: new Array(this.question.multi_stem.length).fill(''),
      selectMenuIndex: -1,
    };
  },
  created() {
    this.initAnswer();
  },
  methods: {
    initAnswer(){
        this.answer=new Array(this.question.multi_stem.length).fill('');
    },
    selectMenu(index){
        if(this.selectMenuIndex>=0){
            this.selectMenuIndex=-1;
        }else{
            this.selectMenuIndex=index;
        }
    },
    selectMenuItem(msIndex,optIndex){
        this.answer[msIndex]=this.question.multi_stem[msIndex].option[optIndex];
        this.selectMenuIndex=-1;
    },
    submit(answer) {
      this.submitAnswer(answer);
      this.initAnswer();
    },
  },
};
</script>
<style lang="css">
.multiple-select-text-questions-body {
  width: 100%;
  position: relative;
  background: url(../assets/images/pic-01.png) no-repeat center center;
  background-size: 100% 100%;
}
.head {
  position: absolute;
  top: 0.2rem;
  left: 0;
  right: 0;
  padding: 0 0.5rem;
}
.headBox {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 0.1rem;
  border: 0.1rem solid #fff;
}
.tips {
  width: 0.38rem;
  height: 0.33rem;
  display: block;
  background: url(../assets/images/newsIcon.png) no-repeat;
  background-size: 100%;
}

.selcect {
  width: 58%;
  position: absolute;
  top: 26%;
  left: 22%;
  bottom: 26%;
  right: 28%;
  display: flex;
  justify-content: center;
  flex-direction: column;
  overflow-y: auto;
}
.submit {
  width: 0.98rem;
  height: 0.98rem;
  background: url(../assets/images/submitBtn.png) no-repeat center center;
  background-size: 100% 100%;
  cursor: pointer;
  margin-left: 0.2rem;
}
.qtText {
  height: 0.5rem;
  display: flex;
  justify-content: center;
  flex-direction: column;
}
.redBorder {
  border-bottom: 2px solid #f00;
  display: inline-block;
}
.tree {
  background-color: #f2b891;
  padding: 0.03rem 0.03rem;
  border-radius: 0.05rem;
  width: 50%;
  margin-left: 0.4rem;
}
.treeDiv {
  background-color: #fffdf5;
  border: 0.01rem solid #e2995e;
  border-radius: 0.04rem;
  height: 100%;
  padding: 0 0.03rem;
}
.arrowDown {
  background-color: #f9e3d7;
  position: absolute;
  top: 0rem;
  bottom: 0rem;
  right: 0rem;
  padding: 0 0.05rem;
  border-radius: 0 0.03rem 0.03rem 0;
}
.arrowDown span {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
}
.arrowDown span:after {
  content: "";
  display: block;
  width: 0.25rem;
  height: 0.19rem;
  background: url(../assets/images/arrowDown.png) no-repeat center center;
  margin-top: 0.02rem;
}
.treeBox {
  background-color: #ffe4cc;
  border: 1px solid #e5a674;
  border-radius: 0.05rem;
  position: absolute;
  left: 0;
  top: 0.31rem;
  right: 0;
  z-index: 4;
}
.treeBox ul li {
  font-size: 0.16rem;
  color: #333;
  padding: 0.03rem 0.05rem;
  cursor: pointer;
}
.treeBox ul li:hover {
  background-color: #fffdf5;
}
.pob {
  position: absolute;
  right: 0.2rem;
  bottom: 0.2rem;
}
</style>